;(function(){
    class Swiper{
        constructor(e){
            this.$e=e;
            this.imgIndex=0;
            this.tempIndex=0;
            // 所有li标签
            this.$oLis=this.$e.find("ul>li");
            // ol
            this.$oL=this.$e.find("ol");


            this.$oLis.each((index)=>{
                this.$oL.append($(`<li class=${index==0?'current':''}>${index+1}</li>`));
            })

            // 克隆
            this.$oLis.first().clone(true).appendTo(this.$e.find("ul"));
            this.timer=setInterval(()=>{
                this.imgIndex++;
                this.tempIndex++;
                this.autoPlay.call(this);
            },1500)
            
            this.mouseHandler();
            this.clickHand();
        }


        autoPlay(){
            if(this.imgIndex>5){
                this.imgIndex=1;
                this.$e.find("ul").css({
                    left:0
                })
            }
            this.$e.find("ul").animate({
                left:this.imgIndex*-500
            },1000)
            this.$oL.children().eq(this.tempIndex).addClass("current").siblings().removeClass("current");
        }

        mouseHandler(){
            let self=this;
            this.$e.on("mouseenter",function(){
                clearInterval(self.timer)
            }).on("mouseleave",function(){
                clearInterval(self.timer)

                self.timer=setInterval(()=>{
                    self.imgIndex++;
                    self.tempIndex++;
                    self.autoPlay.call(self);
                },1500)
            })
        }

        clickHand(){
            let self=this;
            this.$e.on("click","ol>li",function(){
                let $index=$(this).index();
                self.tempIndex=self.imgIndex=$index;
                self.autoPlay()
            })
        }



    }

    $.fn.extend({
        swiper(){
            new Swiper(this);
        }
    })
})()

$(function(){
    $(".all").swiper();
})